package com.food.restaurantpro.objects;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Reservation {
	private String reservationId;
	private String reservationDate;
	private String reservationTime;
	private String reservationNumber;
	private String reservationMemberCode;
	private String reservationStatus;
	
	public Reservation() {
		super();
	}
	
	public Reservation(String reservationId,
			String reservationDate, String reservationTime,
			String reservationNumber, String reservationMemberCode,
			String reservationStatus) {
		super();
		this.reservationId = reservationId;
		this.reservationDate = reservationDate;
		this.reservationTime = reservationTime;
		this.reservationNumber = reservationNumber;
		this.reservationMemberCode = reservationMemberCode;
		this.reservationStatus = reservationStatus;
	}

	public String getReservationId() {
		return reservationId;
	}

	public void setReservationId(String reservationId) {
		this.reservationId = reservationId;
	}
	
	public String getReservationDate() {
		return reservationDate;
	}
	
	public void setReservationDate(String reservationDate) {
		this.reservationDate = reservationDate;
	}
	
	public String getReservationDateWithEE() {
		SimpleDateFormat ddmmyyyy = new SimpleDateFormat("dd/MM/yyyy");  
		SimpleDateFormat eeeeeddmmyyyy = new SimpleDateFormat("EEEE, dd/MM/yyyy");  
		try {  
		    Date date = ddmmyyyy.parse(reservationDate);
		    return eeeeeddmmyyyy.format(date);
		} catch (ParseException e) {  
		    // TODO Auto-generated catch block  
		    e.printStackTrace();  
		}
		return reservationDate;
	}
	
	public String getReservationTime() {
		return reservationTime;
	}
	
	public String getReservationTimeWithPM() {
		try {
		    final SimpleDateFormat sdf = new SimpleDateFormat("H:mm");
		    final Date dateObj = sdf.parse(reservationTime);
		    return new SimpleDateFormat("K:mm aa").format(dateObj);
		} catch (final ParseException e) {
		    e.printStackTrace();
		}
		return reservationTime;
	}
	
	public void setReservationTime(String reservationTime) {
		this.reservationTime = reservationTime;
	}

	public String getReservationNumber() {
		return reservationNumber;
	}
	
	public String getReservationNumberWithText() {
		if(reservationNumber.compareTo("1") == 0) {
			return reservationNumber + " person";
		}
		return reservationNumber + " people";
	}

	public void setReservationNumber(String reservationNumber) {
		this.reservationNumber = reservationNumber;
	}

	public String getReservationMemberCode() {
		return reservationMemberCode;
	}

	public void setReservationMemberCode(String reservationMemberCode) {
		this.reservationMemberCode = reservationMemberCode;
	}

	public String getReservationStatus() {
		return reservationStatus;
	}

	public void setReservationStatus(String reservationStatus) {
		this.reservationStatus = reservationStatus;
	}

	public String getSubmitReservationParams() {
		String params = "";
		try {
			params = "&date_reservation=" + URLEncoder.encode(reservationDate, "UTF-8");
			params += "&time_reservation=" + URLEncoder.encode(reservationTime, "UTF-8");
			params += "&number_reservation=" + reservationNumber;
			params += "&generate_id=" + reservationMemberCode;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return params;
	}
	
	public String getCloseReservationParams() {
		String params = "&reservation_id=" + reservationId;
		params += "&reservation_parameter=wpcf-reservation_status";
		params += "&reservation_value=0";
		return params;
	}
	
	public String getUpdateReservationParams() {
		String params = "";
		try {
			params = "&reservation_id=" + reservationId;
			params += "&reservation_date=" + URLEncoder.encode(reservationDate, "UTF-8");
			params += "&time_reservation=" + URLEncoder.encode(reservationTime, "UTF-8");
			params += "&number_reservation=" + reservationNumber;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return params;
	}
}
